package com.erp.gather.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.gather.domain.bo.ErpSellerCollectProductBo;
import com.erp.gather.domain.vo.ErpSellerCollectProductVo;
import com.erp.gather.service.IErpSellerCollectProductService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 个人采集商品
 *
 * @author erp
 * @date 2023-06-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerCollectProduct")
public class ErpSellerCollectProductController extends BaseController {

	private final IErpSellerCollectProductService iErpSellerCollectProductService;

	/**
	 * 查询个人采集商品列表
	 */
	@SaCheckPermission("seller:sellerCollectProduct:list")
	@GetMapping("/list")
	public TableDataInfo<ErpSellerCollectProductVo> list(ErpSellerCollectProductBo bo, PageQuery pageQuery) {
		return iErpSellerCollectProductService.queryPageList(bo, pageQuery);
	}

	/**
	 * 获取个人采集商品详细信息
	 *
	 * @param id 主键
	 */
	@SaCheckPermission("seller:sellerCollectProduct:query")
	@GetMapping("/{id}")
	public R<ErpSellerCollectProductVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
		return R.ok(iErpSellerCollectProductService.queryById(id));
	}

	/**
	 * 新增个人采集商品
	 */
	@SaCheckPermission("seller:sellerCollectProduct:add")
	@Log(title = "个人采集商品", businessType = BusinessType.INSERT)
	@RepeatSubmit()
	@PostMapping()
	public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerCollectProductBo bo) {
		return toAjax(iErpSellerCollectProductService.insertByBo(bo));
	}

	/**
	 * 修改个人采集商品
	 */
	@SaCheckPermission("seller:sellerCollectProduct:edit")
	@Log(title = "个人采集商品", businessType = BusinessType.UPDATE)
	@RepeatSubmit()
	@PutMapping()
	public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerCollectProductBo bo) {
		return toAjax(iErpSellerCollectProductService.updateByBo(bo));
	}

	@RepeatSubmit()
	@PostMapping("/staging")
	public R<Void> staging(@RequestBody ErpSellerCollectProductBo bo) {
		return toAjax(iErpSellerCollectProductService.staging(bo));
	}

	/**
	 * 删除个人采集商品
	 *
	 * @param ids 主键串
	 */
	@SaCheckPermission("seller:sellerCollectProduct:remove")
	@Log(title = "个人采集商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
		return toAjax(iErpSellerCollectProductService.deleteWithValidByIds(Arrays.asList(ids), true));
	}

	@GetMapping("/publish")
	public R<Object> publish(Long sellerCollectProId) {
		return iErpSellerCollectProductService.publish(sellerCollectProId);
	}
	
	@GetMapping("/publishBatch/{ids}")
	public R<Object> publishBatch( @PathVariable Long[] ids) {
		return iErpSellerCollectProductService.publishBatch(Arrays.asList(ids));
	}
	
	/**
	 * 忽略测试
	 * @return
	 */
	@GetMapping("/ignoreTest")
	public R<Object> ignoreTest(Long sellerCollectProId) {
		return iErpSellerCollectProductService.ignoreTest(sellerCollectProId);
	}
	
	/**
	 * 根据商品id合并规格
	 *
	 * @return
	 */
	@GetMapping("/updateCateGoryProById")
	public R<Void> updateCateGoryProById(Long proId) {
		iErpSellerCollectProductService.updateCateGoryProById(proId);
		return R.ok();
	}
	
	/**
	 * 把个人采集库有，公共采集库没有的，复制到公共采集库中
	 * @return
	 */
	@GetMapping("/copyToPublic")
	public R<Void> copyToPublic() {
		iErpSellerCollectProductService.copyToPublic();
		return R.ok();
	}
	
//	/**
//	 * 同步平台商品
//	 * @return
//	 */
//	@GetMapping("/syncProErp")
//	public R<Void> syncProErp(Long proId) {
//		iErpSellerCollectProductService.syncProErp(proId);
//		return R.ok();
//	}

}
